﻿using System;
using System.Windows;
using NetBay.Core.BusinessEntities;

using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using NetBay.Core.BusinessEntities.Workflow;
using Rio.Framework.Pages.AppCode.Models;

namespace Rio.Framework.Pages.Workflow.Models
{
    public class GridViewSelector : StyleSelector
    {
        #region Methods

        public override Style SelectStyle(object p_oItem, DependencyObject p_oContainer)
        {
            var style =  new Style(typeof(GridViewRow));
            var row = (GridViewRow)p_oContainer;
            
            if (p_oItem is MessageFlowDisp)
            {
                var obj = (MessageFlowDisp)p_oItem;
                if (obj.GroupId != 0)
                {

                    if (obj.MyDocEtat == 0)
                    {
                        style.Setters.Add(new Setter(GridViewRow.FontWeightProperty, FontWeights.Bold));
                    }
                    else
                    {
                        style.Setters.Add(new Setter(GridViewRow.FontWeightProperty, FontWeights.Normal));
                    }
                }
                else
                {
                    int result = DateTime.Compare(obj.LastReadDate, obj.LastActionDate);
                    if (result < 0)
                    {
                        style.Setters.Add(new Setter(GridViewRow.FontWeightProperty, FontWeights.Bold));
                    }
                    else
                    {
                        style.Setters.Add(new Setter(GridViewRow.FontWeightProperty, FontWeights.Normal));
                    }
                }
            }
            else
            {
                ObservableKeyValuePair<WorkflowInstance, Folder> w = p_oItem as ObservableKeyValuePair<WorkflowInstance, Folder>;

                if (w.Key.IsRead)
                {
                    style.Setters.Add(new Setter(GridViewRow.FontWeightProperty, FontWeights.Normal));
                }
                else
                {
                    style.Setters.Add(new Setter(GridViewRow.FontWeightProperty, FontWeights.Bold));
                }
            }

            return style;
        }

        #endregion Methods
    }
}